package com.example.demo.service;

import com.example.demo.common.UserSessionTools;
import com.example.demo.entity.ArticleInfo;
import com.example.demo.entity.UserInfo;
import com.example.demo.entity.vo.ArticleInfoVO;
import com.example.demo.mapper.ArticleMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
//@EnableScheduling
public class ArticleService {
    @Autowired
    private ArticleMapper articleMapper;
    Logger logger = LoggerFactory.getLogger(ArticleService.class);
    public int add(ArticleInfo articleInfo){
        return articleMapper.add(articleInfo);
    }
    public ArticleInfo getDetailByIdAndUid(Integer id, Integer uid){
        return  articleMapper.getDetailByIdAndUid(id,uid);
    }
    public int update(ArticleInfo articleInfo){
        return articleMapper.update(articleInfo);
    }
    public ArticleInfoVO getDetail(Integer id){
        return articleMapper.getDetail(id);
    }
    public int addRcount(Integer id){
            return articleMapper.addRcount(id);
    }
    public List<ArticleInfo> getListByUid(Integer uid){
        return articleMapper.getListByUid(uid);
    }
    public  int del(Integer id,Integer uid){
        return  articleMapper.del(id,uid);
    }
    public List<ArticleInfo> getListByPage(Integer pageSize,Integer offset){
        return articleMapper.getListByPage(pageSize,offset);
    }
    public int getCount(){
        return articleMapper.getCount();
    }

    public int editSave(ArticleInfo articleInfo){
        return articleMapper.editSave(articleInfo);
    }

    public List<ArticleInfo> getDaftListByUid(Integer uid){
        return articleMapper.getDraftListByUid(uid);
    }
    public int timeoutUpdate(ArticleInfo articleInfo){
        return  articleMapper.timeoutUpdate(articleInfo);
    }

    public int addtimeout(ArticleInfo articleInfo){
        return articleMapper.addtimeout(articleInfo);
    }
    //todo：开启一个线程
//    @Scheduled(cron = "0 0/5 * * * ?") // 每5分钟执行一次
//    @Scheduled(fixedRate = 5000) // 每隔5秒执行一次

}
